package com.itheima.cloud.user.controller;

import com.itheima.cloud.pojo.User;
import com.itheima.cloud.response.UserOrderVo;
import com.itheima.cloud.user.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Description:
 * @Version: V1.0
 */
@RestController
@RequestMapping("user")
@RefreshScope  // 刷新本地环境
@Api(value = "用户管理", tags = "User", description = "用户管理API")
public class UserController {

    @Autowired
    UserService userService;

    @Value("${user.username}")
    private String userName;


    /**
     * 查询用户信息
     * @param username 主键
     * @return User
     */
    @GetMapping("findUserById/{username}")
    @ApiOperation(value = "查询用户信息")
    public User findUser(@PathVariable("username") String username) {

        System.out.println("从配置文件中获取的user.username = " + userName);

        return userService.findUser(username);
    }


    /**
     * 查询用户信息和用户所有的订单列表
     * @param username
     * @return
     */
    @GetMapping("findOrderByUserId")
    @ApiOperation(value = "查询用户信息和用户所有的订单列表")
    public UserOrderVo findOrderByUserId(@RequestParam("username") String username) {
        return userService.findOrderByUserId(username);
    }

}
